package HashTable;

import java.util.Arrays;

public class _242_ValidAnagram {
    public boolean isAnagram(String s, String t) {
        char[] cs = s.toCharArray();
        char[] ct = t.toCharArray();
        Arrays.sort(cs);
        Arrays.sort(ct);
        if (cs.length == ct.length) {
            for(int i=0;i<cs.length;i++) {
                if (cs[i] != ct[i]) {
                    return false;
                }
            }
        } else {
            return false;
        }
        return true;
    }

    public boolean isAnagram1(String s, String t) {
        int[] counts = new int[26];
        for (char c : s.toCharArray()) {
            counts[c - 'a']++;
        }
        for (char c : t.toCharArray()) {
            counts[c - 'a']--;
        }
        for (int i : counts) {
            if (i != 0) {
                return false;
            }
        }
        return true;
    }
}
